package com.cn.wanxi.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.PageBean;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.CodeType;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/product/findAll")
public class ProductFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String page = req.getParameter("page");
        String pageSize = req.getParameter("limit");
        String name = req.getParameter("name");
        PageBean<ProductModel> pageBean = new PageBean<>();
        pageBean.setPage(Tool.pageToInt(page));
        pageBean.setPageSize(Tool.pageSizeToInt(pageSize));
        ProductModel productModel=new ProductModel();
        productModel.setPageBean(pageBean);

        ProductService productService=new ProductServiceImpl();
        PageBean bean=productService.findAll(productModel);
//        ResultModel model=new ResultModel();
//        model.setData(bean);
//        model.setCode(CodeType.SUCCESS_CODE);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("bean", bean);
        resp.getWriter().println(jsonObject);
    }
}
